package com.antilia.infomaresme.config.modules;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

import com.antilia.infomaresme.data.dao.hibernate.CategoriesDaoHibernateImp;
import com.antilia.infomaresme.data.dao.hibernate.CategoryAlertsDao;
import com.antilia.infomaresme.data.dao.hibernate.ImageInfosDao;
import com.antilia.infomaresme.data.dao.hibernate.ItemEventsDaoHibernateImp;
import com.antilia.infomaresme.data.dao.hibernate.ItemNewsDaoHibernateImp;
import com.antilia.infomaresme.data.dao.hibernate.ItemsDaoHibernateImp;
import com.antilia.infomaresme.data.dao.hibernate.UserItemAlertsDao;
import com.antilia.infomaresme.data.dao.hibernate.UserMessagesDaoHibernateImp;
import com.antilia.infomaresme.data.dao.hibernate.UsersDao;
import com.antilia.infomaresme.data.dao.interfaces.ICategoriesDao;
import com.antilia.infomaresme.data.dao.interfaces.ICategoryAlertsDao;
import com.antilia.infomaresme.data.dao.interfaces.IImageInfosDao;
import com.antilia.infomaresme.data.dao.interfaces.IItemEventsDao;
import com.antilia.infomaresme.data.dao.interfaces.IItemNewsDao;
import com.antilia.infomaresme.data.dao.interfaces.IItemsDao;
import com.antilia.infomaresme.data.dao.interfaces.IUserItemAlertsDao;
import com.antilia.infomaresme.data.dao.interfaces.IUserMessagesDao;
import com.antilia.infomaresme.data.dao.interfaces.IUsersDao;
import com.antilia.infomaresme.data.dataobjects.Category;
import com.antilia.infomaresme.data.dataobjects.CategoryAlert;
import com.antilia.infomaresme.data.dataobjects.ImageInfo;
import com.antilia.infomaresme.data.dataobjects.Item;
import com.antilia.infomaresme.data.dataobjects.ItemEvent;
import com.antilia.infomaresme.data.dataobjects.ItemNews;
import com.antilia.infomaresme.data.dataobjects.User;
import com.antilia.infomaresme.data.dataobjects.UserItemAlert;
import com.antilia.infomaresme.data.dataobjects.UserMessage;
import com.antilia.infomaresme.data.services.IAuthenticator;
import com.antilia.infomaresme.data.services.IImageService;
import com.antilia.infomaresme.data.services.impl.Authenticator;
import com.antilia.infomaresme.data.services.impl.FileSystemImageService;
import com.google.inject.AbstractModule;
import com.wideplay.warp.persist.PersistenceService;
import com.wideplay.warp.persist.UnitOfWork;

/**
 * @author Richard Wilkinson - richard.wilkinson@jweekend.com
 *
 */
public class Module extends AbstractModule {

	/* (non-Javadoc)
	 * @see com.google.inject.AbstractModule#configure()
	 */
	@Override
	protected void configure() {
		/*
		if(initData())
		{
			bind(DataInitialiser.class).asEagerSingleton();
		}
		*/

		//warp persist stuff
		install(PersistenceService.usingHibernate()
				.across(UnitOfWork.REQUEST)
				.buildModule());

		////hibernate stuff
		AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
		annotationConfiguration.configure();
		annotationConfiguration.addAnnotatedClass(Category.class);
		annotationConfiguration.addAnnotatedClass(CategoryAlert.class);
		annotationConfiguration.addAnnotatedClass(Item.class);
		annotationConfiguration.addAnnotatedClass(User.class);
		annotationConfiguration.addAnnotatedClass(ImageInfo.class);
		annotationConfiguration.addAnnotatedClass(ItemNews.class);
		annotationConfiguration.addAnnotatedClass(ItemEvent.class);
		annotationConfiguration.addAnnotatedClass(UserItemAlert.class);
		annotationConfiguration.addAnnotatedClass(UserMessage.class);
		annotationConfiguration.setInterceptor(new EventsInterceptor());
		bind(Configuration.class).toInstance(annotationConfiguration);

		
		//dao stuff
		bind(ICategoriesDao.class).to(CategoriesDaoHibernateImp.class);
		bind(ICategoryAlertsDao.class).to(CategoryAlertsDao.class);

		bind(IItemsDao.class).to(ItemsDaoHibernateImp.class);
		bind(IItemNewsDao.class).to(ItemNewsDaoHibernateImp.class);
		bind(IUsersDao.class).to(UsersDao.class);
		bind(IImageInfosDao.class).to(ImageInfosDao.class);
		bind(IItemEventsDao.class).to(ItemEventsDaoHibernateImp.class);
		bind(IUserItemAlertsDao.class).to(UserItemAlertsDao.class);
		bind(IUserMessagesDao.class).to(UserMessagesDaoHibernateImp.class);
		
		bind(IImageService.class).to(FileSystemImageService.class);
		bind(IAuthenticator.class).to(Authenticator.class);
	}

	protected boolean initData()
	{
		return true;
	}

}
